package advanced.practice._1011;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
         int N=scanner.nextInt();

         List<Student>students=new ArrayList<>();
         for(int i=0;i<N;i++){
             students.add(new Student(scanner.next(),scanner.next().charAt(0),scanner.next(),scanner.nextInt()));
         }
         students.sort(new Comparator<Student>() {
             @Override
             public int compare(Student o1, Student o2) {
                 if(o1.gender==o2.gender){
                     return o1.grade-o2.grade;
                 }
                 return o2.gender-o1.gender;
             }
         });

         Student boy=null;
         Student girl=null;
         if(N>0){
            boy=students.get(0);
            girl=students.get(N-1);
         }

         boolean NA=false;

        if(girl!=null&&girl.gender=='F'){
            System.out.println(girl.name+" "+girl.ID);
        }else{
            System.out.println("Absent");
            NA=true;
        }

         if(boy!=null&&boy.gender=='M'){
             System.out.println(boy.name+" "+boy.ID);
         }else{
            System.out.println("Absent");
             NA=true;
         }

        if (NA) {
            System.out.println("NA");
        }else {
            System.out.println(girl.grade-boy.grade);
        }
    }

    static class Student{
        String name;
        char gender;
        String ID;
        int grade;

        public Student(String name, char gender, String ID, int grade) {
            this.name = name;
            this.gender = gender;
            this.ID = ID;
            this.grade = grade;
        }
    }
}
